package pl.edu.agh.experts.diseases.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComboBox;
import javax.swing.JSpinner;

import pl.edu.agh.experts.diseases.QuestionProvider;
import pl.edu.agh.experts.diseases.QuestionStrategy;
import pl.edu.agh.experts.diseases.QuestionStrategyProvider;

public class SetupWindowListener implements ActionListener {

	private final JComboBox combo;
	private final JSpinner spinner;
	private final SetupWindow setupWindow;

	public SetupWindowListener(JComboBox combo, JSpinner spinner, SetupWindow setupWindow) {
		this.combo = combo;
		this.spinner = spinner;
		this.setupWindow = setupWindow;
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		Setup.setStrategy(new QuestionStrategyProvider((QuestionStrategy) combo.getSelectedItem()));
		QuestionProvider.setStrategy(new QuestionStrategyProvider((QuestionStrategy) combo.getSelectedItem()));
		Setup.setStopValue((Integer) spinner.getValue() * 0.01);
		setupWindow.dispose();
		MainWindow mainWindow = new MainWindow();
		QuestionProvider.setQuestionStopValue(Setup.getStopValue());
	}

}
